package com.situ.view;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class MainView {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		StudentView studentView = null;
		
		// 序列化
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Object.dat"));
            studentView = (StudentView) ois.readObject();
            ois.close();
        } catch (ClassNotFoundException e) {
            System.out.println("文件不匹配");
        } catch (IOException e) {
            System.out.println();
        }
		
		if (studentView == null) {
		    studentView = new StudentView();
        }
		char key;
		boolean flag = true;
		while (flag) {
			// 功能跳转1.查看所有学生 2.添加新生 3.按姓名查看学生 4.按专业查找学生 0.退出系统
			key = '0';
			key = studentView.Menu();
			switch (key) {
			case '1':
				studentView.getAllStudents();
				break;
			case '2':
				studentView.addStudent();
				break;
			case '3':
				studentView.findStudentByName();
				break;
			case '4':
				studentView.findStudentByMajor();
				break;
			case '0':
				flag = false;
				break;
			default:
				break;
			}
		}
		
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Object.dat"));
        oos.writeObject(studentView);
        oos.flush();
        oos.close();
		
		
	}

}
